package com.rppowell.pixie.swing;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

public class PixieJMenuBar extends JMenuBar {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private JMenuItem spriteViewMenuItem;
	private JMenuItem mapsViewMenuItem;
	
	public PixieJMenuBar(PixieListener listener) {
		JMenu menu;
		
		menu = new JMenu("File");
		menu.setMnemonic(KeyEvent.VK_F);
		add(menu);
		
		JMenuItem menuItem;
		
		menuItem = new JMenuItem("New", KeyEvent.VK_N);
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.ALT_MASK));
		menuItem.setActionCommand(listener.commandGuiNewProject.getCommandString());
		menuItem.addActionListener(listener);
		menu.add(menuItem);
		
		menuItem = new JMenuItem("New Test Project", KeyEvent.VK_N);
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.ALT_MASK));
		menuItem.setActionCommand(listener.commandGuiNewTestProject.getCommandString());
		menuItem.addActionListener(listener);
		menu.add(menuItem);

                menu.addSeparator();
		
		menuItem = new JMenuItem("Open", KeyEvent.VK_O);
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.ALT_MASK));
                menuItem.setEnabled(false);
		menu.add(menuItem);
		
		menu.addSeparator();
		
		menuItem = new JMenuItem("New Sprite Set");
		menuItem.setActionCommand(listener.commandGuiNewSpriteSet.getCommandString());
		menuItem.addActionListener(listener);
		menu.add(menuItem);
		
		menuItem = new JMenuItem("New Sprite");
		menuItem.setActionCommand(listener.commandGuiNewSprite.getCommandString());
		menuItem.addActionListener(listener);
		menu.add(menuItem);
		
		menuItem = new JMenuItem("New Map");
		menuItem.setActionCommand(listener.commandGuiNewMap.getCommandString());
		menuItem.addActionListener(listener);
		menu.add(menuItem);
		
		menu.addSeparator();
		
		menuItem = new JMenuItem("Import", KeyEvent.VK_I);
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, ActionEvent.ALT_MASK));
		menuItem.setActionCommand(listener.commandGuiImportDialog.getCommandString());
		menuItem.addActionListener(listener);
		menu.add(menuItem);
		
		menu.addSeparator();

		menuItem = new JMenuItem("Exit", KeyEvent.VK_X);
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.ALT_MASK));
		menuItem.setActionCommand(listener.commandGuiExit.getCommandString());
		menuItem.addActionListener(listener);
		menu.add(menuItem);
		
		menu = new JMenu("View");
		menu.setMnemonic(KeyEvent.VK_V);
		
		spriteViewMenuItem = new JMenuItem("Sprite Mode");
		spriteViewMenuItem.setActionCommand(listener.commandGuiSwitchToSpriteMode.getCommandString());
		spriteViewMenuItem.addActionListener(listener);
		menu.add(spriteViewMenuItem);
		
		mapsViewMenuItem = new JMenuItem("Maps Mode");
		mapsViewMenuItem.setActionCommand(listener.commandGuiSwitchToMapsMode.getCommandString());
		mapsViewMenuItem.addActionListener(listener);
		menu.add(mapsViewMenuItem);

		add(menu);
	}

	public void setPixieUIState(PixieUIState state) {
		spriteViewMenuItem.setEnabled(state.isSpriteMenuEnabled());
		mapsViewMenuItem.setEnabled(state.isMapsMenuEnabled());
	}
}
